import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '主页', icon: 'dashboard' }
    }]
  },
  {
    path: '/customer',
    component: Layout,
    children: [
      {
        path: '',
        name: 'CustomerManager',
        component: () => import('@/views/customer/index'),
        meta: { title: '顾客管理', icon: 'el-icon-user-solid' }
      }
    ]
  },
  {
    path: '/doctor',
    component: Layout,
    children: [
      {
        path: '',
        name: 'DoctorManager',
        component: () => import('@/views/doctor/index'),
        meta: { title: '医生管理', icon: 'el-icon-s-custom' }
      }
    ]
  },
  {
    path: '/drug',
    component: Layout,
    children: [
      {
        path: '',
        name: 'DrugManager',
        component: () => import('@/views/drug/index'),
        meta: { title: '药品管理', icon: 'el-icon-s-check' }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    children: [
      {
        path: '',
        name: 'OrderManager',
        component: () => import('@/views/order/index'),
        meta: { title: '订单管理', icon: 'el-icon-s-promotion' }
      }
    ]
  },
  {
    path: '/deal',
    component: Layout,
    children: [
      {
        path: '',
        name: 'DealManager',
        component: () => import('@/views/deal/index'),
        meta: { title: '处方管理', icon: 'el-icon-s-flag' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
